<template>
	<view style="position: relative;">
		<view class="logo">
			<image src="../../static/icon/logo.png" mode="aspectFit"></image>
		</view>
		<view class="title">
			<word class="text" zh="老挝韻達物流" lao="Yunda"></word>
		</view>
		<login />

		<!-- 更新 -->
		<yomol-upgrade :type="upgradeType" :url="upgradeUrl" :title="title" :content="upgradeContent" ref="yomolUpgrade"></yomol-upgrade>
	</view>
</template>

<script>
	import login from "./login/login.vue"
	import yomolUpgrade from '@/components/yomol-upgrade/yomol-upgrade.vue'

	export default {
		components: {
			yomolUpgrade,
			login
		},
		data() {
			return {
				title: '发现新版本',
				upgradeType: 'pkg', //pkg 整包 wgt 升级包
				upgradeContent: '优化', //更新内容
				upgradeUrl: 'http://47.57.79.152:8031/apk/LYD3KDY_GooglePlay.apk', //更新地址
			}
		},
		mounted() {
			// #ifdef APP-PLUS
			this.checkVersionClick()
			// #endif
		},
		methods: {
			/*
			 * 检测版本升级
			 */
			checkVersionClick() {
				plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
					this.$api.getUpdateVersionApi().then(result => {
						let response = result.resultParam.systemConfig
						if (response.value !== widgetInfo.version) {
							this.title += response.value
							this.$refs.yomolUpgrade.show()
						}
					})
				})
			}
		},
		onShow() {
			if (this.$store.getters.token) {
				this.$api.getUserApi()
					.then((res) => {
						uni.hideLoading();
						if (res.status === 200) {
							uni.switchTab({
								url: '/pages/person/index',
							})
						}
						return this.$api.getParentApi()
					}).then(result => {
						this.$store.dispatch('setSite', result.resultParam.parent)
					})
			}
		}
	}
</script>

<style lang="scss">
	.logo {
		display: flex;
		justify-content: center;
		padding-top: 157rpx;

		image {
			width: 194rpx;
			height: 141rpx;
		}
	}

	.title {
		margin-top: 40rpx;
		text-align: center;

		text {
			font-weight: bold;
			font-size: 36rpx;
			color: #fec802;
		}
	}
</style>
